﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace AgendaManager.Service
{
    public class CarpetaDAO : DAOBase
    {
        public static bool CreateFoldersStructure(Obra obra)
        {
            try
            {
                Carpeta carpeta = new Carpeta();
                carpeta.ObraId = obra.Id;

                carpeta.Tipo = "Ivos y Notas";
                int nextId = GetNextId(carpeta);
                carpeta.Id = nextId;
                CreateEntity(carpeta);

                carpeta.Tipo = "Fotos";
                nextId = GetNextId(carpeta);
                carpeta.Id = nextId;
                CreateEntity(carpeta);

                carpeta.Tipo = "Planos";
                nextId = GetNextId(carpeta);
                carpeta.Id = nextId;
                CreateEntity(carpeta);

                return true;
            }
            catch (Exception)
            {

                throw;
            }
        }


        internal static List<Carpeta> RetrieveEntitiesWhere(object dto, string where)
        {
            List<Carpeta> dtos = new List<Carpeta>();

            DataTable dt = GetDataTableWhere(dto, where);

            if (dt.Rows.Count > 0)
                dtos = LlenarCarpetas(dto, dt);

            return dtos;
        }

        private static List<Carpeta> LlenarCarpetas(object dto, DataTable dt)
        {
            List<Carpeta> dtos = new List<Carpeta>();

            foreach (DataRow dr in dt.Rows)
            {
                Carpeta aux = new Carpeta();
                PoblarObjetoDesdeDataRow(aux, dr);

                dtos.Add(aux);
            }

            return dtos;
        }
    }
}